﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using MODEL;
using Microsoft.International.Converters.PinYinConverter;
namespace winUi
{
    public partial class FormTool : Form
    {
        public FormTool()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                new ServiceRuKu().qingkong();
                MessageBox.Show("清空完成");
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            List<Stock> stocks = new BllStock().GetAll();
            foreach (Stock s in stocks)
            {
                if (string.IsNullOrEmpty(s.PY))
                {
                    s.PY = ToPY(s.GoodsName);
                    new BllStock().Update(s);
                }
                
            }
            List<RuKu> rukus = new BllRuKu().GetAllList();
            foreach (RuKu r in rukus)
            {
                if (string.IsNullOrEmpty(r.PY))
                {
                    r.PY = ToPY(r.GoodName);
                    new BllRuKu().Update(r);
                }
               
            }
            MessageBox.Show("拼音简码更新！");
        }
        public string ToPY(string str)
        {
            StringBuilder sb = new StringBuilder();
            foreach (char c in str)
            {
                if (ChineseChar.IsValidChar(c))
                {
                    ChineseChar cc = new ChineseChar(c);
                    sb.Append(cc.Pinyins[0].Substring(0, 1));
                }


            }
            return sb.ToString();
        }

    }
}
